# load("xxx.RData")



### INDIVIDUAL LEVEL VARIABLES

# A) Personal Characteristics

# Experienced author indicator and number:

exper_auth <- authors[names(authorcounts),"pre_experience"] >= K

N_auth_exp <- sum(exper_auth)

# Researcher skill:

Z <- as.character( authors[names(authorcounts), "skill_code"] )

Z[is.na(Z)] <- "000"

Z <- as.factor(Z)

###

# B) Lists of Project Characteristics

# Project category of each paper (by each author):

temp1 <- as.numeric(X_P[unlist(paperlist)])

X_list <- relist(temp1, skeleton=paperlist)
	names(X_list) <- names(paperlist)

# Actual impact of each paper (by each author):

temp2 <- as.numeric(articles[unlist(paperlist),"impact"])

Y_list <- relist(temp2, skeleton=paperlist)
	names(Y_list) <- names(paperlist)

# Sort by actual impact:

temp3 <- lapply(Y_list, order, decreasing=TRUE)

for (a in 1:N_auth_full)  {
	temp <- X_list[[a]]
	X_list[[a]] <- temp[temp3[[a]]]
	temp <- Y_list[[a]]
	Y_list[[a]] <- temp[temp3[[a]]]
}

# Keep the predicted impact and category of top *L* papers:

for (a in which(lengths(paperlist) > L))  {
	temp <- X_list[[a]]
	X_list[[a]] <- temp[1:L]
	temp <- Y_list[[a]]
	Y_list[[a]] <- temp[1:L]
}

# Sort by X_P:

temp3 <- lapply(X_list, order, decreasing=TRUE)

for (a in 1:N_auth_full)  {
	temp <- X_list[[a]]
	X_list[[a]] <- temp[temp3[[a]]]
	temp <- Y_list[[a]]
	Y_list[[a]] <- temp[temp3[[a]]]
}

# Clean up:

rm(a, temp, temp1, temp2, temp3)
